package com.qfedu.meidijiaju.controller;


import com.qfedu.meidijiaju.common.ResponseData;
import com.qfedu.meidijiaju.entity.UserAndTopic;
import com.qfedu.meidijiaju.service.TopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(tags = "用户关注话题模块接口")
@RestController
public class TopicController {
    @Autowired
    private TopicService topicService;

    @ApiOperation("查询用户关注话题，需要传递所查询用户uid")
    @RequestMapping(value = "/topic/queryTopic",method = RequestMethod.GET)
    public ResponseData<List<UserAndTopic>> queryTopic(int uid) {
        ResponseData<List<UserAndTopic>> responseData = new ResponseData<>();
        List<UserAndTopic> result = topicService.queryTopic(uid);
        int count = topicService.queryCount(uid);

        if (result != null) {
            responseData.setCode(0);
            responseData.setData(result);
            responseData.setCount(count);
        }
        return responseData;
    }

    @ApiOperation("添加用户关注话题")
    @RequestMapping(value = "/topic/add",method = RequestMethod.GET)
    public ResponseData<String> addTopic(UserAndTopic userAndTopic) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = topicService.addTopic(userAndTopic);
        if (result) {
            responseData.setCode(0);
            responseData.setMsg("添加话题成功");
        }

        return responseData;
    }

    @ApiOperation("删除用户关注话题,需要传递用户uid,话题tid")
    @RequestMapping(value = "/topic/delate",method = RequestMethod.GET)
    public ResponseData<String> deleteTopic(UserAndTopic userAndTopic) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = topicService.daleteTopic(userAndTopic);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("删除话题成功");
        }

        return responseData;
    }
}
